<?php


namespace app\mall\model\Goods;



use think\facade\Db;

class GoodsCateRelationModel
{
    /**
     * 数据表名
     * @var string
     */
    protected $name = "goods_cate_relation";

    /**
     * 获取商品分类
     * @param $where
     * @return mixed
     * @throws
     */
    public static function getGoodsCateRelationJoinWhere($where)
    {
        array_push($where, ['gc.is_show','=','1']);
        $field = ['gc.cate_name', 'gc.pic as cate_pic, gc.sort, gc.pid'];
        $list = Db::name('goods_cate_relation as gcr')
            ->join('goods_cate as gc', function ($join) {
                $join->on('gcr.cate_id', '=', 'gc.id');
            })
            ->field($field)
            ->where($where)
            ->select()->toArray();
        return $list;
    }

    /**
     * 根据条件查询多条
     * @param $where
     * @return array
     * @throws
     */
    public static function getGoodsCateRelationWhereMore($where)
    {
        $list = Db::name('goods_cate_relation')->where($where)->select()->toArray();
        return $list;
    }

    /**
     * 统计
     * @param $where
     * @return int
     */
    public static function getGoodsCateRelationCountWhere($where)
    {
        $count = Db::name("goods_cate_relation")->where($where)->count();
        return $count;
    }

    /**
     * 批量添加
     * @param $data
     * @return int
     */
    public static function addGoodsCateRelation($data)
    {
        $flag = Db::name("goods_cate_relation")->insertAll($data);
        return $flag;
    }

    /**
     * 删除
     * @param $where
     * @return int
     * @throws
     */
    public static function delGoodsCateRelationWhere($where)
    {
        $flag = Db::name('goods_cate_relation')->where($where)->delete();
        return $flag;
    }
}
